package com.atguigu.lease.web.app.custom.converter;


import com.atguigu.lease.model.enums.LeaseStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class StringToItemTypeConverter implements Converter<String, LeaseStatus> {

    @Override
    public LeaseStatus convert(String source) {
        for (LeaseStatus leaseStatus : LeaseStatus.values()) {
            if (leaseStatus.getCode().equals(Integer.valueOf(source))){
                return leaseStatus;
            }
        }

        throw new IllegalArgumentException("code非法");
    }
}
